package day07;

import java.util.Arrays;
import java.util.Scanner;

public class CalTotaAvg {
    public static void main(String[] args) {
        System.out.println("输入评委数量！！");
        int num = getScanner();
        System.out.println("一共有"+num+"个评委，请依次输入评分");
        double[] data = inputData(num);
        data = deleteMax(data);
        data = deleteMin(data);
        System.out.println(Arrays.toString(data));
        double mean = arrayMean(data);
        System.out.println("平均分为"+mean);
    }
    //输入
    public static int getScanner(){
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        return a;
    }

    //输入评委分数
    public static double[]inputData(int count){
        double[] data = new double[count];
        for (int i = 0; i < data.length; i++) {
            double a = getScanner();
            data[i] = a;
        }
        return data;
    }

    //去掉最高分
    public static double[] deleteMax(double[] array){
        double max = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j <= array.length-1; j++) {
                if (array[i]>array[j]){
                    max = array[j];
                    array[j] = array[i];
                    array[i] = max;
                }
            }
        }
        array = Arrays.copyOf(array,array.length-1);
        return array;
    }

    //去掉最低分
    public static double[] deleteMin(double[] array){
        double min = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j <= array.length-1; j++) {
                if (array[i]<array[j]){
                    min = array[j];
                    array[j] = array[i];
                    array[i] = min;
                }
            }
        }
        array = Arrays.copyOf(array,array.length-1);
        return array;
    }

    //输出数组总分
    public static double arraySum(double[] array){
        double sum = 0.0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        return sum;
    }

    //输出数组平均分
    public static double arrayMean(double[] array){
        double mean = arraySum(array)/(array.length);
        return mean;
    }
}
